package cn.bdqn.web;

import cn.bdqn.entity.Air;
import cn.bdqn.entity.District;
import cn.bdqn.service.AirService;
import cn.bdqn.service.DistrictService;
import cn.bdqn.service.impl.AirServiceImpl;
import cn.bdqn.service.impl.DistrictServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


@WebServlet(value = "/air/toMaintain")
public class AirToMaintainServlet extends HttpServlet{
    /*
    4. 跳转到空气质量维护页面
    路径:
        GET		http://localhost/air/toMaintain
    参数:
        id = integer(必传项)
    响应:
        1. 查询出指定的空气质量信息,放到request域中
        2. 查询出全部的区域信息,放到request域中
        3. 转发到/WEB-INF/air_maintain.jsp
     */

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1. 接收参数
        String idStr = req.getParameter("id");
        //2. 封装参数.
        Integer id = null;
        if(idStr != null){
            id = Integer.valueOf(idStr);
        }

        //3. 查询出指定的空气质量信息,放到request域中
        AirService airService = new AirServiceImpl();
        Air air = airService.findById(id);
        req.setAttribute("air",air);

        //4. 查询出全部的区域信息,放到request域中
        DistrictService districtService = new DistrictServiceImpl();
        List<District> list = districtService.findAll();
        req.setAttribute("list",list);

        //5. 转发到/WEB-INF/air_maintain.jsp
        req.getRequestDispatcher("/WEB-INF/air_maintain.jsp").forward(req,resp);


    }
}
